package com.bdqn.t350.dao.impl;

import com.bdqn.t350.dao.BaseDao;
import com.bdqn.t350.dao.UsersDao;
import com.bdqn.t350.entity.Users;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

public class UsersDaoImp extends BaseDao implements UsersDao {

    Connection conn = null;
    PreparedStatement pstmt = null;
    ResultSet rs = null;

    @Override
    public int login(Users users) {
        String sql = "select count(1) from users where uname = ? and upwd = ?";
        int count = 0;
        try {
            conn = this.getConnection();
            pstmt = conn.prepareStatement(sql);
            pstmt.setObject(1, users.getUname());
            pstmt.setObject(2, users.getUpwd());
            rs = pstmt.executeQuery();
            while (rs.next()) {
                count = rs.getInt(1);
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            this.closeAll(conn, pstmt, rs);
        }
        return count;
    }
}
